Results 1 to 5 of 5

Thread: Array question

  1. #1

    Default Array question

    Can you use an array to spawn a trigger in different place and have them use same model? or would you need to make a separate trigger for each thing?

    like say spawn a crate in 3 locations that explodes when triggered, would you make the array for model or trigger?

    I read Sor's post http://www.x-null.net/forums/showthr...ll=1#post12654 here but to be honest I don't have any idea what it means...lol

    I've done it with teleports with help from you guys but that was for " random " spots (below from above post)
    Code:
    local.array = makeArray
    ( -432.25 1078.15 23.56 ) ( 0 175 0 )
    ( -1560.30 -127.01 -22.43 ) ( 0 -95 0 )
    ( -1560.30 -127.01 -22.43 ) ( 0 -95 0 )
    ( 560.23 -66.56 -47.20 ) ( 0 -126 0 )
    endArray
    
    for (local.i = 1; local.i <= local.array.size; local.i++) {
    	local.static = spawn script_model model "static/indycrate.tik"
    	local.static.origin = local.array[local.i][1]
    	local.static.angles = local.array[local.i][2]
    	local.static solid
    	local.static nodamage
    }
    so that will spawn a crate in those cords. would I do the same thing for the trigger? or do you thread the trigger after " local.static nodamage"

  2. #2

    Default

    With this code you can spawn the trigger with the model together at the same time:

    Code:
    for(local.i = 1;local.i <= local.array.size;local.i++)
    {
    local.static = spawn script_model model "static/indycrate.tik"
    	local.static.origin = local.array[local.i][1]
    	local.static.angles = local.array[local.i][2]
    	local.static solid
    	local.static nodamage
    
        local.n = 2
       
    
    local.tr[local.n] = spawn trigger_multiple 
    local.tr[local.n].origin = ( local.array[local.i][1] )
    local.tr[local.n] setsize ( -10 -10 -10 ) ( 10 10 10 )
    local.tr[local.n] setthread tr
    
    local.n++
    }
    On the trigger you have to always put a different targetname if not when someone shot in one of the objects is going to remove all the objects at the same time.

  3. #3

    Default

    ok thanks see if I can do what I want.

  4. #4
    Developer Sor's Avatar
    Join Date
    Aug 2010
    Location
    The Medieval City of Bruges
    Posts
    747

    Default

    Quote Originally Posted by DoubleKill View Post
    Code:
    for(local.i = 1;local.i <= local.array.size;local.i++)
    {
        local.static = spawn script_model model "static/indycrate.tik";
        local.static.origin = local.array[local.i][1];
        local.static.angles = local.array[local.i][2];
        local.static solid;
        local.static nodamage;
    
        local.n = 2
       
    
    local.tr[local.n] = spawn trigger_multiple 
    local.tr[local.n].origin = ( local.array[local.i][1] )
    local.tr[local.n] setsize ( -10 -10 -10 ) ( 10 10 10 )
    local.tr[local.n] setthread tr
    
    local.n++
    }
    The above makes no sense because variable n will be set to 2 every time. You actually don't need to keep a list of the triggers if you use the same targetname for each one.
    for(local.i = 1;local.i <= local.array.size;local.i++)
    {
        local.box = spawn script_model model "static/indycrate.tik"
        local.box.origin = local.array[local.i][1]
        local.box.angles = local.array[local.i][2]
        local.box solid
        local.box nodamage
    
        local.trig = spawn trigger_multiple "targetname" "mytrigger"
        local.trig.origin = ( local.array[local.i][1] )
        local.trig setsize ( -10 -10 -10 ) ( 10 10 10 )
        local.trig setthread triggerThread
    }

    And to iterate over your triggers, simply do
    for(local.i = 1; local.i <= $mytrigger.size; local.i++) {
          $mytrigger[local.i] //...
    }

    This has the advantage that the game is now responsible for managing this array. If you spawn a new entity with this targetname, it will be added to the array. If you remove an entity with this targetname, it will be also removed from the array.

    Quote Originally Posted by DoubleKill View Post
    On the trigger you have to always put a different targetname if not when someone shot in one of the objects is going to remove all the objects at the same time.
    If you delete them by using their targetname, this would be true. However, self refers to the trigger entity in the thread called by the trigger, so you can just do this:
    triggerThread:
        local.player = parm.other;
        // do trigger stuff
        self remove;
    end;
    Last edited by Sor; December 19th, 2015 at 04:45 PM.
    Morpheus Script (MoH) => You try to shoot yourself in the foot only to discover that MorpheusScript already shot your foot for you.

  5. #5

    Default

    well I got it working but I didn't use Doublekills way and I just read yours, thanks to both of you all knowledge is helpful and I save all this stuff to text files to refer back later on. What I did was ripped off part of Gotchs capture manon thing and combined it to what I had and it seems to work good.

Posting Permissions

  • You may not post new threads
  • You may not post replies
  • You may not post attachments
  • You may not edit your posts
  •